package com.zhentao.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.*;

@Configuration//表示当前是一个配置类
//开关 --开启springmvc
@EnableWebMvc
@ComponentScan(basePackages = "com.zhentao.controller")
public class SpringmvcConfig implements WebMvcConfigurer {
    //静态资源的配置

    /**
     * css文件夹存放css文件
     * js文件夹存放js文件
     * imgs文件存放图片
     * views文件夹存放html
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //允许直接访问静态资源

        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/imgs/**").addResourceLocations("/imgs/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/views/**").addResourceLocations("/views/");
    }
    //项目启动，进入指定页面


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        RedirectViewControllerRegistration re = registry.addRedirectViewController("/", "/views/loginn.html");
    }

    //        处理中文乱码 - 过滤器
    public CharacterEncodingFilter getCharacterEncodingFilter(){
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("utf-8");

        return characterEncodingFilter;
    }
}
